// subpages0/stepPoint/stepRank/stepRank.js
const app = getApp();
import { request } from '../../../utils/request.js'
Page({
  data: {
    showLoading: true,
    noMoretip: false,
    page: 0
  },

  onLoad: function (e) {
    var that = this;
    that.requestRankList();
  },
  requestRankList: function () {
    var that = this;
    var data = {};
    var page = that.data.page;
    data.map = 'applet_step_rank';
    data.page = page;
    request({
      data:data,
      showTip: true,
      pointer: { page: this, fname: "requestRankList" },
    }).then(res => {
      console.log('测试封装requst步数排行榜', res.data.data);
      that.setData({
        myInfo: res.data.data.my
      })
      var allArr = [];
      var initArr = that.data.rankList;
      var curArr = res.data.data.list;
      var lastPageLength = curArr.length;
      if (page > 0) {
        allArr = initArr.concat(curArr);
      } else {
        allArr = res.data.data.list;
      }
      that.setData({
        rankList: allArr
      })
      if (lastPageLength < 10) {
        that.setData({
          noMoretip: true,
          showLoading: false
        });
      }
      console.log(that.data.rankList);
    }).catch(err => {
      console.log(err);
      if (page <= 0) {
        that.setData({
          commentList: []
        })
      } else {
        that.setData({
          noMoretip: true,
          showLoading: false
        });
      }
    })
  },
  onPullDownRefresh: function () {
    this.setData({
      page: 0,
      noMoretip: false,
      showLoading: true
    });
    this.requestRankList();
    console.log("下拉刷新");
  },
  onReachBottom: function () {
    var that = this;
    console.log("到达页面底部")
    var isMore = that.data.noMoretip;
    var page = that.data.page;
    page++;
    that.setData({
      page: page
    });
    if (isMore) {
      console.log("已完成或正在加载");
    } else {
      that.requestRankList();
    }
  }
})